package com.health.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.health.system.dto.EvaluationResultDTO;
import com.health.system.entity.HealthData;
import com.health.system.service.HealthDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author baomidou
 * @since 2024-06-22
 */
@Validated
@Api(tags = "健康数据管理")
@RestController
public class HealthDataController {
    @Autowired
    private HealthDataService healthDataService;

    @GetMapping("/admin/health/data")
    public IPage<HealthData> getAllHealthData(@RequestParam(value = "current", defaultValue = "1") Long current,
                                              @RequestParam(value = "size", defaultValue = "10") Long size) {
        return healthDataService.getAllHealthData(current, size);
    }

    @ApiOperation(value = "新增用户健康数据")
    @PostMapping("/admin/health/data")
    public void addHealthData(@RequestBody HealthData healthData) {
        healthDataService.addHealthData(healthData);
    }

    @ApiOperation(value = "修改用户健康数据")
    @PutMapping("/admin/health/data")
    public void updateHealthData(@RequestBody HealthData healthData) {
        healthDataService.updateHealthData(healthData);
    }

    @ApiOperation(value = "删除用户健康数据")
    @DeleteMapping("/admin/health/data/{id}")
    public void deleteHealthData(@PathVariable Integer id) {
        healthDataService.deleteHealthData(id);
    }

    @ApiOperation(value = "查询评估结果")
    @GetMapping("/admin/health/data/result/{id}")
    public EvaluationResultDTO evaluationResult(@PathVariable Integer id) {
        return healthDataService.evaluationResult(id);
    }
}
